# -*- coding: utf-8 -*-
import os

import allure
from PIL import ImageGrab

from Util import config, logger
from Util.util import getNowTime


class _BaseClass(object):
    def __enter__(self):
        return self

    def __exit__(self, *args):
        if args[0]:
            img = ImageGrab.grab(all_screens=True)
            imgPath = f"{os.path.join(config.imagePath, 'wrong_picture', getNowTime().replace(':', '：'))}.png"
            img.save(imgPath)
            allure.attach.file(imgPath, '环境异常', allure.attachment_type.PNG)
            return False
        else:
            return True
